-- @owner:yangjian
-- @date:2024-4-2
-- @testpoint:1.去除大对象使用限制，测试对大对象的函数进行explain操作，合理报错

--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_use_case0003_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(101);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(200);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_use_case0003_1();

--环境准备
drop table if exists t_opengauss_large_object_use_case0003_1 cascade;
CREATE TABLE t_opengauss_large_object_use_case0003_1 (loid oid,fd int);

--step1:对lo_creat进行explain;expect:成功
explain SELECT lo_creat(100);

--step2:对lo_create进行explain;expect:成功
explain SELECT lo_creat(101);

--step3:对lo_open,loread,lowrite,lo_close进行explain;expect:成功
begin;
explain SELECT lo_open(100,CAST(x'20000' | x'40000' AS integer));
explain select lowrite (0,'aaaaaaaaaa');
explain select loread (0, 6);
explain select lo_close (0);
end;
/

--step4:对lo_seek,lo_seek64进行explain;expect:成功
begin;
explain SELECT lo_open(100,CAST(x'20000' | x'40000' AS integer));
explain select lo_lseek(0,5,0);
explain select lo_lseek64(0,5,5);
explain select lo_close (0);
end;
/

--step5:对lo_tell,lo_tell64进行explain;expect:成功
begin;
explain SELECT lo_open(100,CAST(x'20000' | x'40000' AS integer));
explain select lo_tell(0);
explain select lo_tell64(0);
explain select lo_close (0);
end;
/

--step6:对lo_truncate,lo_truncate64进行explain;expect:成功
begin;
explain SELECT lo_open(100,CAST(x'20000' | x'40000' AS integer));
explain select lowrite (0,'aaaaaaaaaa');
explain select lo_truncate(0,2);
explain select lo_truncate64(0,1);
explain select lo_close (0);
end;
/

--step7:对lo_put,lo_get进行explain;expect:成功
explain select lo_put(100,6,'aaaaaa');
explain select lo_get(100,6,6);

--step8:对lo_from_bytea进行explain;expect:成功
explain select lo_from_bytea(200,'aaaaaa');

--step9:对lo_unlink进行explain;expect:成功
explain select lo_unlink(100);

--清理环境
select lo_unlink(loid) from pg_largeobject;
select f_opengauss_large_object_use_case0003_1();
drop table if exists t_opengauss_large_object_use_case0003_1 cascade;
drop function f_opengauss_large_object_use_case0003_1();

